﻿<local:BaseListWithToolbarContentFrame x:Class="InfFront.InfoViews.WPF.PlotFrame"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:InfFront.InfoViews.WPF"
    xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
    Height="Auto" Width="Auto" MinWidth="300" MinHeight="300"
    >
    <UserControl.Resources>
        <local:ColorTitleToColorConverter x:Key="titleToColor"/>
    </UserControl.Resources>

    <Grid x:Name="plotFrame" MinHeight="100">
        <Grid.Background>
            <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                <GradientStop Offset="0" Color="{Binding Path=VisualSettings.PrimaryGridColor, FallbackValue=White}"/>
                <GradientStop Offset="1" Color="{Binding Path=VisualSettings.SecondaryGridColor, FallbackValue=Azure}"/>
            </LinearGradientBrush>
        </Grid.Background>

        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="200" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition MinWidth="100"  Width="{Binding Path=VisualSettings.PlotLegendWidth, FallbackValue=100, Mode=TwoWay}"/>
        </Grid.ColumnDefinitions>

        <d3:ChartPlotter Name="plotter" Grid.Column="0" Background="Transparent" IsTabStop="False" LegendVisible="False">
            <d3:DateTimeAxis Name="xDateTimeAxis" Visibility="Hidden" Placement="Bottom" />
            <d3:DateTimeAxis Name="yDateTimeAxis" Visibility="Hidden" Placement="Left" />
        </d3:ChartPlotter>

        <GridSplitter Grid.Column="1" ShowsPreview="True" Width="2"
                      HorizontalAlignment="Center" VerticalAlignment="Stretch">
            <GridSplitter.Background>
                <LinearGradientBrush>
                    <GradientStop Offset="0" Color="{Binding Path=VisualSettings.SecondaryGridColor, FallbackValue=Azure}"/>
                    <GradientStop Offset="1" Color="{Binding Path=VisualSettings.PrimaryGridColor, FallbackValue=White}"/>
                </LinearGradientBrush>
            </GridSplitter.Background>
        </GridSplitter>

        <ItemsControl x:Name="legendsList" Grid.Column="2"
                          Grid.IsSharedSizeScope="True">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition SharedSizeGroup="FieldTitles" />
                                <ColumnDefinition SharedSizeGroup="FieldValues" />
                            </Grid.ColumnDefinitions>
                            <WrapPanel Grid.Column="0" VerticalAlignment="Center">
                                <TextBlock Text="{Binding Path=Title}">
                                        <TextBlock.Foreground>
                                            <SolidColorBrush Color="{Binding Path=VisualSettings.ColumnPlotColor, FallbackValue=Black, Converter={StaticResource titleToColor}}" />
                                        </TextBlock.Foreground>
                                    </TextBlock>
                                <TextBlock Text=" - " />
                                </WrapPanel>
                            <ComboBox IsEditable="False" Grid.Column="1" MinWidth="100"
                                          ItemsSource="{DynamicResource legendKeys}"
                                          Text="{Binding Path=VisualSettings.ColumnPlotColor, Mode=TwoWay}"
                                          >
                            </ComboBox>
                        </Grid>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

    </Grid>
</local:BaseListWithToolbarContentFrame>
